<extend name="Public/base" />

<block name="body">
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>商品列表</h2>
    </div>
    <div class="cf">
        <div class="fl">
            <a class="btn btn-default" href="{:U('Product/add')}">新 增</a>
            <a class="btn btn-default" href="{:U('Product/orderExport')}">导出</a>
        </div>
        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <a class="btn btn-warning" href="{:U('index?inventory=0')}">库存不足商品</a>
                <a class="btn btn-success" href="{:U('index?recommend=1')}">置顶商品</a>
                <a class="btn btn-primary" href="{:U('index?status=1')}">上架商品</a>
                <a class="btn btn-danger" href="{:U('index?status=0')}">下架商品</a>
            </div>
            <div class="sleft">
                <input type="text" name="sku" class="search-input" value="{:I('sku')}" placeholder="请输入商品批次">
                <input type="text" name="name" class="search-input" value="{:I('name')}" placeholder="请输入商品名称">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('index')}"><i class="btn-search"></i></a>
            </div>
        </div>
    </div>


    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
                    <th class="">商品编号</th>
                    <th class="">商品批次</th>
                    <th class="" style="width:160px;">商品名称</th>
                    <th class="">规格</th>
                    <!--<th class="" style="width:140px;">简介</th>-->
                    <th class="">价格</th>
                    <th class="">合同价</th>
                    <th class="">库存</th>
                    <th class="">产地</th>
                    <!--<th class="">修改日期</th>-->
                    <th class="">操作</th>
                </tr>
            </thead>
            <tbody>
            <notempty name="_list">
                <volist name="_list" id="vo">
                    <tr>
                        <td><input class="ids" type="checkbox" name="id[]" value="{$vo.id}" /></td>
                        <td>{$vo.id} </td>
                        <td>{$vo.sku} </td>
                        <td>{$vo.name} </td>
                        <td>{$vo.quantity} </td>
                        <!--<td>{$vo.intro}</td>-->
                        <th class=""><span style="color: red;font-weight: bold;">{$vo.price}</span></th>
                        <th class=""><span style="color: red;font-weight: bold;">{$vo.contract_price}</span></th>
                        <th class="">{$vo.inventory}</th>
                        <th class="">{$vo.origin}</th>
                        <!--<td>{$vo.lastupdate|time_format}</td>-->
                        <td><a href="{:U('Product/edit?id='.$vo['id'])}" class="btn btn-primary">编辑商品</a>
                            <eq name="vo.status" value="0">
                            <a href="{:U('Product/puton?id='.$vo['id'])}" class="confirm ajax-get  btn btn-primary" style="background-color: red;">上架</a>
                    <else/>
                    <a href="{:U('Product/putoff?id='.$vo['id'])}" class="confirm ajax-get  btn btn-primary">下架</a>
                    </eq>
                    <a href="{:U('Product/del?id='.$vo['id'])}" class="confirm ajax-get   btn btn-warning">删除</a>
                      <eq name="vo.recommend" value="0">
                         <!--<a href="{:U('Product/recommend?id='.$vo['id'])}&status=1" class="confirm ajax-get  btn btn-default">置顶</a>-->
                         <a  data-id="{$vo.id}" class="recommend btn btn-default">置顶</a>
                      <else/>
                          <a href="{:U('Product/recommend?id='.$vo['id'])}&status=0" class="confirm ajax-get  btn btn-danger">取消置顶({$vo.recommend})</a>
                       </eq>
                    </td>
                    </tr>
                </volist>
                <else/>
                <td colspan="9" class="text-center"> aOh! 暂时还没有内容! </td>
            </notempty>
            </tbody>
        </table>
    </div>
    <div class="page">
        {$_page}
    </div>
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">
        $(".recommend").click(function () {
            var id = $(this).data("id");
            var status = prompt("请输入推荐序号","");
            if(status == ""||status == undefined){
                status = 1;
            }
            var url = "{:U('Product/recommend')}";
            var data = {id:$(this).data("id"),status:status};
            $.ajax({
                url: url,
                data: data,
                success: function(obj){
                    alert("置顶成功");
                }
            });
            location.reload()
        });
        //搜索功能
        $("#search").click(function () {
            var url = $(this).attr('url');
            var query = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, '');
            query = query.replace(/^&/g, '');
            if (url.indexOf('?') > 0) {
                url += '&' + query;
            } else {
                url += '?' + query;
            }
            window.location.href = url;
        });
        //回车搜索
        $(".search-input").keyup(function (e) {
            if (e.keyCode === 13) {
                $("#search").click();
                return false;
            }
        });

        //导航高亮
        highlight_subnav('{:U('Product/index')}');
    </script>
</block>
